package leetcode.code0367;

public class Solution3 extends Solution367 {

	@Override
	public boolean isPerfectSquare(int num) {
		long l = 0;
		long r = num;
		while (l <= r) {
			long mid = ((r - l) >> 1) + l;
			long mul = mid * mid;
			if (mul == num) {
				return true;
			} else if (mul < num) {
				l = mid + 1;
			} else {
				r = mid - 1;
			}
		}
		return false;
	}

	public static void main(String[] args) {
		Solution3 so = new Solution3();
		so.debug4();
		so.debug3();
		so.debug1();
		so.debug2();
//		System.out.println(so.isPerfectSquare(255));
//		System.out.println(so.isPerfectSquare(256));
//		System.out.println(so.isPerfectSquare(1024));
//		System.out.println(so.isPerfectSquare(1025));
//		System.out.println(Math.sqrt(255));
	}

}
